import { defineStore } from "pinia";
import { getC1, getC2, getC3 } from "@/api/attr";
import { CategoryResponseData } from "@/api/attr/type";
export default defineStore("category", {
  state() {
    return {
      //存储一级分类的数据
      c1Arr: [],
      //存储一级分类的ID
      c1Id: "",
      //存储对应一级分类下二级分类的数据
      c2Arr: [],
      //收集二级分类的ID
      c2Id: "",
      //存储三级分类的数据
      c3Arr: [],
      //存储三级分类的ID
      c3Id: "",
    };
  },
  actions: {
    async getC1() {
      const result: CategoryResponseData = await getC1();
      if (result.code == 200) {
        this.c1Arr = result.data;
      }
    },
    async getC2() {
      const result: CategoryResponseData = await getC2(this.c1Id);
      if (result.code == 200) {
        this.c2Arr = result.data;
      }
    },
    async getC3() {
      const result: CategoryResponseData = await getC3(this.c2Id);
      if (result.code == 200) {
        this.c3Arr = result.data;
      }
    },
  },
  getters: {},
});
